home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / distutils / bcppcompiler.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  8KB  |  330 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''distutils.bcppcompiler
  5.  
  6. Contains BorlandCCompiler, an implementation of the abstract CCompiler class
  7. for the Borland C++ compiler.
  8. '''
  9. __revision__ = '$Id: bcppcompiler.py,v 1.18 2004/11/10 22:23:13 loewis Exp $'
  10. import sys
  11. import os
  12. from distutils.errors import DistutilsExecError, DistutilsPlatformError, CompileError, LibError, LinkError, UnknownFileError
  13. from distutils.ccompiler import CCompiler, gen_preprocess_options, gen_lib_options
  14. from distutils.file_util import write_file
  15. from distutils.dep_util import newer
  16. from distutils import log
  17.  
  18. class BCPPCompiler(CCompiler):
  19.     '''Concrete class that implements an interface to the Borland C/C++
  20.     compiler, as defined by the CCompiler abstract class.
  21.     '''
  22.     compiler_type = 'bcpp'
  23.     executables = { }
  24.     _c_extensions = [
  25.         '.c']
  26.     _cpp_extensions = [
  27.         '.cc',
  28.         '.cpp',
  29.         '.cxx']
  30.     src_extensions = _c_extensions + _cpp_extensions
  31.     obj_extension = '.obj'
  32.     static_lib_extension = '.lib'
  33.     shared_lib_extension = '.dll'
  34.     static_lib_format = shared_lib_format = '%s%s'
  35.     exe_extension = '.exe'
  36.     
  37.     def __init__(self, verbose = 0, dry_run = 0, force = 0):
  38.         CCompiler.__init__(self, verbose, dry_run, force)
  39.         self.cc = 'bcc32.exe'
  40.         self.linker = 'ilink32.exe'
  41.         self.lib = 'tlib.exe'
  42.         self.preprocess_options = None
  43.         self.compile_options = [
  44.             '/tWM',
  45.             '/O2',
  46.             '/q',
  47.             '/g0']
  48.         self.compile_options_debug = [
  49.             '/tWM',
  50.             '/Od',
  51.             '/q',
  52.             '/g0']
  53.         self.ldflags_shared = [
  54.             '/Tpd',
  55.             '/Gn',
  56.             '/q',
  57.             '/x']
  58.         self.ldflags_shared_debug = [
  59.             '/Tpd',
  60.             '/Gn',
  61.             '/q',
  62.             '/x']
  63.         self.ldflags_static = []
  64.         self.ldflags_exe = [
  65.             '/Gn',
  66.             '/q',
  67.             '/x']
  68.         self.ldflags_exe_debug = [
  69.             '/Gn',
  70.             '/q',
  71.             '/x',
  72.             '/r']
  73.  
  74.     
  75.     def compile(self, sources, output_dir = None, macros = None, include_dirs = None, debug = 0, extra_preargs = None, extra_postargs = None, depends = None):
  76.         (macros, objects, extra_postargs, pp_opts, build) = self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs)
  77.         if not extra_preargs:
  78.             pass
  79.         compile_opts = []
  80.         compile_opts.append('-c')
  81.         if debug:
  82.             compile_opts.extend(self.compile_options_debug)
  83.         else:
  84.             compile_opts.extend(self.compile_options)
  85.         for obj in objects:
  86.             
  87.             try:
  88.                 (src, ext) = build[obj]
  89.             except KeyError:
  90.                 continue
  91.  
  92.             src = os.path.normpath(src)
  93.             obj = os.path.normpath(obj)
  94.             self.mkpath(os.path.dirname(obj))
  95.             if ext == '.res':
  96.                 continue
  97.             
  98.             if ext == '.rc':
  99.                 
  100.                 try:
  101.                     self.spawn([
  102.                         'brcc32',
  103.                         '-fo',
  104.                         obj,
  105.                         src])
  106.                 continue
  107.                 except DistutilsExecError:
  108.                     msg = None
  109.                     raise CompileError, msg
  110.                     continue
  111.                 
  112.  
  113.             
  114.             if ext in self._c_extensions:
  115.                 input_opt = ''
  116.             elif ext in self._cpp_extensions:
  117.                 input_opt = '-P'
  118.             else:
  119.                 input_opt = ''
  120.             output_opt = '-o' + obj
  121.             
  122.             try:
  123.                 self.spawn([
  124.                     self.cc] + compile_opts + pp_opts + [
  125.                     input_opt,
  126.                     output_opt] + extra_postargs + [
  127.                     src])
  128.             continue
  129.             except DistutilsExecError:
  130.                 msg = None
  131.                 raise CompileError, msg
  132.                 continue
  133.             
  134.  
  135.         
  136.         return objects
  137.  
  138.     
  139.     def create_static_lib(self, objects, output_libname, output_dir = None, debug = 0, target_lang = None):
  140.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  141.         output_filename = self.library_filename(output_libname, output_dir = output_dir)
  142.         if self._need_link(objects, output_filename):
  143.             lib_args = [
  144.                 output_filename,
  145.                 '/u'] + objects
  146.             if debug:
  147.                 pass
  148.             
  149.             
  150.             try:
  151.                 self.spawn([
  152.                     self.lib] + lib_args)
  153.             except DistutilsExecError:
  154.                 msg = None
  155.                 raise LibError, msg
  156.             except:
  157.                 None<EXCEPTION MATCH>DistutilsExecError
  158.             
  159.  
  160.         None<EXCEPTION MATCH>DistutilsExecError
  161.         log.debug('skipping %s (up-to-date)', output_filename)
  162.  
  163.     
  164.     def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  165.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  166.         (libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
  167.         if runtime_library_dirs:
  168.             log.warn("I don't know what to do with 'runtime_library_dirs': %s", str(runtime_library_dirs))
  169.         
  170.         if output_dir is not None:
  171.             output_filename = os.path.join(output_dir, output_filename)
  172.         
  173.         if self._need_link(objects, output_filename):
  174.             if target_desc == CCompiler.EXECUTABLE:
  175.                 startup_obj = 'c0w32'
  176.                 if debug:
  177.                     ld_args = self.ldflags_exe_debug[:]
  178.                 else:
  179.                     ld_args = self.ldflags_exe[:]
  180.             else:
  181.                 startup_obj = 'c0d32'
  182.                 if debug:
  183.                     ld_args = self.ldflags_shared_debug[:]
  184.                 else:
  185.                     ld_args = self.ldflags_shared[:]
  186.             if export_symbols is None:
  187.                 def_file = ''
  188.             else:
  189.                 (head, tail) = os.path.split(output_filename)
  190.                 (modname, ext) = os.path.splitext(tail)
  191.                 temp_dir = os.path.dirname(objects[0])
  192.                 def_file = os.path.join(temp_dir, '%s.def' % modname)
  193.                 contents = [
  194.                     'EXPORTS']
  195.                 for sym in []:
  196.                     contents.append('  %s=_%s' % (sym, sym))
  197.                 self.execute(write_file, (def_file, contents), 'writing %s' % def_file)
  198.             objects2 = map(os.path.normpath, objects)
  199.             objects = [
  200.                 startup_obj]
  201.             resources = []
  202.             for file in objects2:
  203.                 (base, ext) = os.path.splitext(os.path.normcase(file))
  204.                 if ext == '.res':
  205.                     resources.append(file)
  206.                     continue
  207.                 objects.append(file)
  208.             
  209.             for l in library_dirs:
  210.                 ld_args.append('/L%s' % os.path.normpath(l))
  211.             
  212.             ld_args.append('/L.')
  213.             ld_args.extend(objects)
  214.             ld_args.extend([
  215.                 ',',
  216.                 output_filename])
  217.             ld_args.append(',,')
  218.             for lib in libraries:
  219.                 libfile = self.find_library_file(library_dirs, lib, debug)
  220.                 if libfile is None:
  221.                     ld_args.append(lib)
  222.                     continue
  223.                 ld_args.append(libfile)
  224.             
  225.             ld_args.append('import32')
  226.             ld_args.append('cw32mt')
  227.             ld_args.extend([
  228.                 ',',
  229.                 def_file])
  230.             ld_args.append(',')
  231.             ld_args.extend(resources)
  232.             if extra_preargs:
  233.                 ld_args[:0] = extra_preargs
  234.             
  235.             if extra_postargs:
  236.                 ld_args.extend(extra_postargs)
  237.             
  238.             self.mkpath(os.path.dirname(output_filename))
  239.             
  240.             try:
  241.                 self.spawn([
  242.                     self.linker] + ld_args)
  243.             except DistutilsExecError:
  244.                 msg = None
  245.                 raise LinkError, msg
  246.             except:
  247.                 None<EXCEPTION MATCH>DistutilsExecError
  248.             
  249.  
  250.         None<EXCEPTION MATCH>DistutilsExecError
  251.         log.debug('skipping %s (up-to-date)', output_filename)
  252.  
  253.     
  254.     def find_library_file(self, dirs, lib, debug = 0):
  255.         if debug:
  256.             dlib = lib + '_d'
  257.             try_names = (dlib + '_bcpp', lib + '_bcpp', dlib, lib)
  258.         else:
  259.             try_names = (lib + '_bcpp', lib)
  260.         for dir in dirs:
  261.             for name in try_names:
  262.                 libfile = os.path.join(dir, self.library_filename(name))
  263.                 if os.path.exists(libfile):
  264.                     return libfile
  265.                     continue
  266.             
  267.         else:
  268.             return None
  269.  
  270.     
  271.     def object_filenames(self, source_filenames, strip_dir = 0, output_dir = ''):
  272.         if output_dir is None:
  273.             output_dir = ''
  274.         
  275.         obj_names = []
  276.         for src_name in source_filenames:
  277.             (base, ext) = os.path.splitext(os.path.normcase(src_name))
  278.             if ext not in self.src_extensions + [
  279.                 '.rc',
  280.                 '.res']:
  281.                 raise UnknownFileError, "unknown file type '%s' (from '%s')" % (ext, src_name)
  282.             
  283.             if strip_dir:
  284.                 base = os.path.basename(base)
  285.             
  286.             if ext == '.res':
  287.                 obj_names.append(os.path.join(output_dir, base + ext))
  288.                 continue
  289.             if ext == '.rc':
  290.                 obj_names.append(os.path.join(output_dir, base + '.res'))
  291.                 continue
  292.             obj_names.append(os.path.join(output_dir, base + self.obj_extension))
  293.         
  294.         return obj_names
  295.  
  296.     
  297.     def preprocess(self, source, output_file = None, macros = None, include_dirs = None, extra_preargs = None, extra_postargs = None):
  298.         (_, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
  299.         pp_opts = gen_preprocess_options(macros, include_dirs)
  300.         pp_args = [
  301.             'cpp32.exe'] + pp_opts
  302.         if output_file is not None:
  303.             pp_args.append('-o' + output_file)
  304.         
  305.         if extra_preargs:
  306.             pp_args[:0] = extra_preargs
  307.         
  308.         if extra_postargs:
  309.             pp_args.extend(extra_postargs)
  310.         
  311.         pp_args.append(source)
  312.         if self.force and output_file is None or newer(source, output_file):
  313.             if output_file:
  314.                 self.mkpath(os.path.dirname(output_file))
  315.             
  316.             
  317.             try:
  318.                 self.spawn(pp_args)
  319.             except DistutilsExecError:
  320.                 msg = None
  321.                 print msg
  322.                 raise CompileError, msg
  323.             except:
  324.                 None<EXCEPTION MATCH>DistutilsExecError
  325.             
  326.  
  327.         None<EXCEPTION MATCH>DistutilsExecError
  328.  
  329.  
  330.